import os
import cv2
import ddddocr
from PIL import Image
from io import BytesIO

path = os.path.dirname(__file__)
path_ = lambda x:os.path.join(path,'data','chi',x)
det = ddddocr.DdddOcr(det=True,show_ad=False)
rec = ddddocr.DdddOcr(show_ad=False)

with open(path_('1_0.png'),'rb') as f:
    data = f.read()

res = det.detection(data)
img = Image.open(path_('1_0.png'))

str_set = {}
for box in res:
    # 裁剪
    str_img = img.crop(box)
    # 初始化缓存对象
    img_bytes = BytesIO()
    # 写入缓存对象
    str_img.save(img_bytes,'img')
    word = rec.classification
    str_set[word] = box
print(res)

